(function ($) {
	Drupal.behaviors.edxModule = {
			attach: function(context, settings) {

        // Check to see if logged into edx.org, if so, hide login stuff
        var $cookie = 'edxloggedin';
        if (document.cookie.indexOf($cookie) >= 0) {
          $('.register-button').hide();
          $('.sign-in').hide();
          $('.howitworks-register-button').hide();
          $('.dashboard').show();
          // @todo We need to be more particular about what we're hiding
          $('header nav .menu li.last').hide();
        }

				function dotdotdotFinish(isTruncated, origContent) {
					$('.newsBrief').animate({
						'opacity' : '1'
					}, 400);
				}

				//MAKE THE ELLIPSIS FOR HOME PAGE NEWS TILES
				if( $('.home-page-tiles-inside').find('.news').get(0) ) {
					//DOT DOT DOT NOT SUPPORT IE7
					if( BrowserDetect.browser != 'Explorer' || BrowserDetect.version != '7' ) {
						if( $('.newsBrief').get(0) ) {
							if( $('.information-big').get(0) ) {
								$('.newsTitle').dotdotdot({
									ellipsis: '...',
									wrap: 'letter',
									watch: 'window'
								});

								if( $('.newsTitle').height() == 22 ) {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 90,
										callback: dotdotdotFinish
									});
								}
								else if( $('.newsTitle').height() == 44 ) {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 60,
										callback: dotdotdotFinish
									});
								}
								else {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 50,
										callback: dotdotdotFinish
									});
								}
							}
							else {
								$('.newsTitle').dotdotdot({
									ellipsis: '...',
									wrap: 'letter',
									watch: 'window'
								});

								if( $('.newsTitle').height() == 22 ) {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 85,
										callback: dotdotdotFinish
									});
								}
								else if( $('.newsTitle').height() == 44 ) {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 60,
										callback: dotdotdotFinish
									});
								}
								else {
									$('.newsBrief').dotdotdot({
										ellipsis: '...',
										wrap: 'word',
										watch: 'window',
										height: 50,
										callback: dotdotdotFinish
									});
								}
							}
						}
					}
				}

				$('[class=course-node]').bind('click', function(object) {
					var $current = $(this);
					var modalid = $current.attr('modalid');
					var selector = '#' + modalid;

					var $parent = $current.parent();
					var $modal = $parent.find(selector);

					$modal.fadeIn();
				});

				//REMOVE THE LAST LINE SEPARATOR
				if( $('.openposition-row').get(0) ) {
					var arr = $('.openposition-row');
					var count = arr.length;
					var $lastChild = arr[count - 1];

					$($lastChild).css('border', 'none');
					$($lastChild).css('padding-bottom', '0px');
				}

				//VERTICAL ALIGN THE PICTURE
				if( $('.news-row').get(0) ) {
					$('.news-row').each(function(){
						var actualHeight = $(this).find('.news-image img').height();
						var parentHeight = $(this).find('.news-image img').parent().height();
						var middleHeight = (parentHeight - actualHeight) / 2;

						$(this).find('.news-image img').css('margin-top', middleHeight);
					});
				}

				//click on course tile and other events
				if( $('.course-tile').get(0) ) {
					$('.course-tile').live('click', function(){ 
						var src = $(this).find('.course-link').attr('href');
						
						window.location = src;
					});

					trimCourseTile();
				}

				function trimCourseTile()
				{
					var maxWidthGreyBar = 597;
					$('.course-tile').find('.bottom').each(function(object) {
						var totalWidth = 0;

						$(this).find('li').each(function(element) {
							totalWidth += $(this).width();
						});

						if( totalWidth > maxWidthGreyBar ) {
							var diff = totalWidth - maxWidthGreyBar;
							var instructorWidth = $('.instructor-list').width();

							$(this).find('.instructor-list').css({
								'width': ( instructorWidth - diff - 50 ) + 'px'
							});
						}
					});
				}

				//click on school slider
				if( $('.school-homepage-logo').get(0) ) {
					$('.school-homepage-logo').click(function(){
						var src = $(this).find('.school-link').attr('href');
						
						window.location = src;
					});
				}

				//change the size of the slider to prevent the new line
				if( $('.schools-slider-container').get(0) ) {
					var totalWidth = 0;

					$('.schools-slider-container').find('.tiles').each(function(){
						totalWidth += $(this).width();
					});

					$('.schools-slider-container').width(totalWidth);
				}

				//EDX SLIDER
				if( $('.home-page-slider-schools').get(0) ) {
					var containerSize = $('.home-page-slider-schools').width();
					var tileWidth = 0;
					var totalWidth = 0;
					
					if( $('.schools-slider-container').width() > containerSize ) {
						// $('.schools-back').fadeIn();
						$('.schools-next').fadeIn();
					}

					$('.schools-slider-container').find('.tiles').each(function(){
						tileWidth = $(this).width();
						totalWidth += $(this).width();
					});	
					
					function scrollNext() {
						var actualMarginLeft = $('.schools-slider-container').css('margin-left');
						actualMarginLeft = actualMarginLeft.replace('px', '');
						actualMarginLeft -= tileWidth;

						if(totalWidth + actualMarginLeft > containerSize - 20){
							$('.schools-back').fadeIn();

							$('.schools-slider-container').animate({
								'margin-left': actualMarginLeft
							}, 300, function(){
								if(totalWidth + actualMarginLeft <= containerSize ){
									$('.schools-next').fadeOut();
								}
							});	
						} 
						else {
							$('.schools-next').fadeOut();
						}
					}

					function scrollBack() {
						var actualMarginLeft = $('.schools-slider-container').css('margin-left');
						actualMarginLeft = parseInt(actualMarginLeft.replace('px', ''));
						actualMarginLeft += parseInt(tileWidth);

						if(totalWidth - actualMarginLeft > containerSize ){
							$('.schools-next').fadeIn();

							$('.schools-slider-container').animate({
								'margin-left': actualMarginLeft
							}, 300, function() {
								console.log(totalWidth);
								console.log(actualMarginLeft);
								console.log(containerSize);

								if( actualMarginLeft >= 0 ){
									$('.schools-back').fadeOut();
								}

							});	
						}
						else {
							$('.schools-back').fadeOut();
						}
					}

          // Initiate forward scroll on initial mouseenter, then run on interval until they mouseoff
          $('.schools-next').mouseenter(scrollNext);
          $('.schools-next')
            .bind('mouseenter', function() { this.iid = setInterval(function() { scrollNext(); }, 1000); })
            .bind('mouseleave', function() { this.iid && clearInterval(this.iid); });

          // Initiate backward scroll on initial mouseenter, then run on interval until they mouseoff
          $('.schools-back').mouseenter(scrollBack);
          $('.schools-back')
            .bind('mouseenter', function() { this.iid = setInterval(function() { scrollBack(); }, 1000); })
            .bind('mouseleave', function() { this.iid && clearInterval(this.iid); });
            
				}

				//set the position of WebForm
				if( $('#contactus-webform').get(0) ) {
					var extraHeight = 100;
					var leftHeight = $('.contactus-left').height();
					var rightHeight = $('.contactus-right').height();

					var difference = 0;

					if( leftHeight < rightHeight ) {
						difference = rightHeight - leftHeight;
					}
					else  {
						difference = leftHeight - rightHeight;
					}

					var margintop = '-' + difference + 'px';

					$('#contactus-webform').css('margin-top', margintop);

					var plusHeight = ($('#contactus-webform').height() - difference) + $('.inside-internal-page').height() + extraHeight;

					$('.inside-internal-page').height(plusHeight);
				}

				//CHANGE THE OVER WITH JAVASCRIPT
				$('.footer').find('.icon').find('img').mouseenter(function(){
					var src = $(this).attr('src');
					var newSrc = src.replace('.png', '');
					newSrc = newSrc + '-over.png';

					$(this).attr('src', newSrc);
				}).mouseleave(function(){
					var src = $(this).attr('src');
					var newSrc = src.replace('-over.png', '');
					newSrc = newSrc + '.png';

					$(this).attr('src', newSrc);
				});

				$('.sign-in, .button-view-this, .register-button').find('img').mouseenter(function(){
					var src = $(this).attr('src');
					var newSrc = src.replace('.png', '');
					newSrc = newSrc + '-over.png';

					$(this).attr('src', newSrc);
				}).mouseleave(function(){
					var src = $(this).attr('src');
					var newSrc = src.replace('-over.png', '');
					newSrc = newSrc + '.png';

					$(this).attr('src', newSrc);
				});

				// scroll to prerequisistes if exists
				if( $('#prerequisites-seemore').get(0) ) {
					if( $("#prerequisites-container").height() < '120' ) {
						$('#prerequisites-seemore').hide();						
					}

					$('#prerequisites-seemore').click(function(){
						$('html, body').animate({
							scrollTop: $("#prerequisites-container").offset().top - 40
						}, 1000);
					});
				} 

				//EVENT WHEN THE USER SELECT THE COURSE STATUS
				if( $('.course-status-filter').get(0) ) {

          // Added 5/23/2013 by Karen Piotrowski
          // This was added to decentralize our course listing url that was previously
          //  hardcoded into the theme. It is intended to be a temporary fix that will
          //  be addressed in greater depth in the theme rewrite.
          var pathCourses = 'course-list';
          if (typeof Drupal.settings.edxtweak != "undefined") {
            if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
              var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
            }
          }

					//change selected class with the url
					var currentURL = window.location.href;
					var coursesURL = pathCourses + '/';
					var queryParts = currentURL.split(coursesURL);

					if( queryParts.length == 2 ) {
						var currentParameters = queryParts[1].split('/');
						if( currentParameters[2] == 'all' ) {
							$('.course-status-all').addClass('selected');
							
							$('.course-status-past').removeClass('selected');
							$('.course-status-current').removeClass('selected');
							$('.course-status-new').removeClass('selected');

						} else if( currentParameters[2] == 'new' ) {
							$('.course-status-new').addClass('selected');
							
							$('.course-status-past').removeClass('selected');
							$('.course-status-current').removeClass('selected');
							$('.course-status-all').removeClass('selected');

						} else if( currentParameters[2] == 'past' ) {
							$('.course-status-past').addClass('selected');
							
							$('.course-status-new').removeClass('selected');
							$('.course-status-current').removeClass('selected');
							$('.course-status-all').removeClass('selected');

						}  else if( currentParameters[2] == 'current' ) {
							$('.course-status-current').addClass('selected');
							
							$('.course-status-past').removeClass('selected');
							$('.course-status-new').removeClass('selected');
							$('.course-status-all').removeClass('selected');
						}
					}
					else if( queryParts.length == 1 ) {
						var coursesURL = 'school/';
						var queryParts = currentURL.split(coursesURL);

						try{


							var currentParameters = queryParts[1].split('/');
							if( currentParameters[1] == 'all' ) {
								$('.course-status-all').addClass('selected');
								
								$('.course-status-past').removeClass('selected');
								$('.course-status-current').removeClass('selected');
								$('.course-status-new').removeClass('selected');

							} else if( currentParameters[1] == 'new' ) {
								$('.course-status-new').addClass('selected');
								
								$('.course-status-past').removeClass('selected');
								$('.course-status-current').removeClass('selected');
								$('.course-status-all').removeClass('selected');

							} else if( currentParameters[1] == 'past' ) {
								$('.course-status-past').addClass('selected');
								
								$('.course-status-new').removeClass('selected');
								$('.course-status-current').removeClass('selected');
								$('.course-status-all').removeClass('selected');

							}  else if( currentParameters[1] == 'current' ) {
								$('.course-status-current').addClass('selected');
								
								$('.course-status-past').removeClass('selected');
								$('.course-status-new').removeClass('selected');
								$('.course-status-all').removeClass('selected');
							}
						}
						catch(error){
							console.log(error);
						}
					}

					var counterWidth = $('.title').find('.counter').width() + 30;
					$('.course-status-filter').css({
						'margin-left' : counterWidth
					});

					$('.course-status-new').click(function(event){
						event.preventDefault();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						var statusNewFilter = 'new';

						console.log(queryParts.length);

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}

							window.location = '/' + pathCourses + '/' + schoolOldFilter + '/' + subjectOldFilter + '/' + statusNewFilter;
						} 
						else if( queryParts.length == 1 ) {
							var coursesURL = 'school/';
							var queryParts = currentURL.split(coursesURL);

							if( queryParts.length == 2 ) {
								var currentParameters = queryParts[1].split('/');

								//ONLY HAVE SCHOOL FILTER
								if( currentParameters.length == 1 ) {
									schoolOldFilter = currentParameters[0];
								}
								else if(currentParameters.length == 2 ){
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
								}
								else {
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
									statusOldFilter = currentParameters[2];
								}

								window.location = '/school/' + schoolOldFilter + '/' + statusNewFilter;
							} 
						}
					});

					$('.course-status-all').click(function(event){
						event.preventDefault();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						var statusNewFilter = 'allcourses';

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}

							window.location = '/' + pathCourses + '/' + schoolOldFilter + '/' + subjectOldFilter + '/' + statusNewFilter;
						} 
						else if( queryParts.length == 1 ) {
							var coursesURL = 'school/';
							var queryParts = currentURL.split(coursesURL);

							if( queryParts.length == 2 ) {
								var currentParameters = queryParts[1].split('/');

								//ONLY HAVE SCHOOL FILTER
								if( currentParameters.length == 1 ) {
									schoolOldFilter = currentParameters[0];
								}
								else if(currentParameters.length == 2 ){
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
								}
								else {
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
									statusOldFilter = currentParameters[2];
								}

								window.location = '/school/' + schoolOldFilter + '/' + statusNewFilter;
							} 
						}
					});

					$('.course-status-current').click(function(event){
						event.preventDefault();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						var statusNewFilter = 'current';

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}

							window.location = '/' + pathCourses + '/' + schoolOldFilter + '/' + subjectOldFilter + '/' + statusNewFilter;
						} 
						else if( queryParts.length == 1 ) {
							var coursesURL = 'school/';
							var queryParts = currentURL.split(coursesURL);

							if( queryParts.length == 2 ) {
								var currentParameters = queryParts[1].split('/');

								//ONLY HAVE SCHOOL FILTER
								if( currentParameters.length == 1 ) {
									schoolOldFilter = currentParameters[0];
								}
								else if(currentParameters.length == 2 ){
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
								}
								else {
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
									statusOldFilter = currentParameters[2];
								}

								window.location = '/school/' + schoolOldFilter + '/' + statusNewFilter;
							} 
						}
					});

					$('.course-status-past').click(function(event){
						event.preventDefault();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						var statusNewFilter = 'past';

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}

							window.location = '/' + pathCourses + '/' + schoolOldFilter + '/' + subjectOldFilter + '/' + statusNewFilter;
						} 
						else if( queryParts.length == 1 ) {
							var coursesURL = 'school/';
							var queryParts = currentURL.split(coursesURL);

							if( queryParts.length == 2 ) {
								var currentParameters = queryParts[1].split('/');

								//ONLY HAVE SCHOOL FILTER
								if( currentParameters.length == 1 ) {
									schoolOldFilter = currentParameters[0];
								}
								else if(currentParameters.length == 2 ){
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
								}
								else {
									schoolOldFilter = currentParameters[0];
									subjectOldFilter = currentParameters[1];
									statusOldFilter = currentParameters[2];
								}

								window.location = '/school/' + schoolOldFilter + '/' + statusNewFilter;
							} 
						}
					});
				}

				//EVENT WHEN THE USER CHANGE SCHOOL FILTER
				if( $('.school-filter').get(0) ) {
					//attach event
					$('.school-filter').find('select').change(function() {
						var schoolNewFilter = $('.school-filter').find('select option:selected').val();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}
						} 
						
						window.location = '/' + pathCourses + '/' + schoolNewFilter + '/' + subjectOldFilter + '/' + statusOldFilter;
					});
				}

				//EVENT WHEN THE USER CHANGE SUBJECT FILTER
				if( $('.subject-filter').get(0) ) {
					//attach event
					$('.subject-filter').find('select').change(function() {
						var subjectNewFilter = $('.subject-filter').find('select option:selected').val();

            // Added 5/23/2013 by Karen Piotrowski
            // This was added to decentralize our course listing url that was previously
            //  hardcoded into the theme. It is intended to be a temporary fix that will
            //  be addressed in greater depth in the theme rewrite.
            var pathCourses = 'course-list';
            if (typeof Drupal.settings.edxtweak != "undefined") {
              if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
                var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
              }
            }

						var currentURL = window.location.href;
						var coursesURL = pathCourses + '/';
						var queryParts = currentURL.split(coursesURL);

						var schoolOldFilter, subjectOldFilter, statusOldFilter = 'all';

						if( queryParts.length == 2 ) {
							var currentParameters = queryParts[1].split('/');

							//ONLY HAVE SCHOOL FILTER
							if( currentParameters.length == 1 ) {
								schoolOldFilter = currentParameters[0];
							}
							else if(currentParameters.length == 2 ){
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
							}
							else {
								schoolOldFilter = currentParameters[0];
								subjectOldFilter = currentParameters[1];
								statusOldFilter = currentParameters[2];
							}
						} 
						
						window.location = '/' + pathCourses + '/' + schoolOldFilter + '/' + subjectNewFilter + '/' + statusOldFilter;
					});
				}

				//change the select box with filter value
				if( $('.subject-filter').get(0) || $('.school-filter').get(0) ) {

          // Added 5/23/2013 by Karen Piotrowski
          // This was added to decentralize our course listing url that was previously
          //  hardcoded into the theme. It is intended to be a temporary fix that will
          //  be addressed in greater depth in the theme rewrite.
          var pathCourses = 'course-list';
          if (typeof Drupal.settings.edxtweak != "undefined") {
            if (typeof Drupal.settings.edxtweak.base_path_edx_courses != "undefined") {
              var pathCourses = Drupal.settings.edxtweak.base_path_edx_courses;
            }
          }

					var currentURL = window.location.href;
					var coursesURL = pathCourses + '/';
					var queryParts = currentURL.split(coursesURL);
					if( queryParts.length == 2 ) {
						var currentParameters = queryParts[1].split('/');

						//ONLY HAVE SCHOOL FILTER
						if( currentParameters.length == 1 ) {
							schoolOldFilter = currentParameters[0].replace(/%20/g, ' ');
						}
						else {
							schoolOldFilter = currentParameters[0].replace(/%20/g, ' ');
							subjectOldFilter = currentParameters[1].replace(/%20/g, ' ');
						}
					}

					$('.school-filter option').each(function() {
						if( $(this).val() == schoolOldFilter ) {
							$(this).attr('selected', 'selected');
						}
					});

					$('.subject-filter option').each(function() {
						if( $(this).val() == subjectOldFilter ) {
							$(this).attr('selected', 'selected');
						}
					});
				}

				//change comment form input submit button
				if( $('.comment-form').get(0) ) {
					$('.comment-form input[type="submit"]').addClass('button-blue');
					$('.comment-form input[type="submit"]').attr('value', 'post');
				}

				//CHANGE LOGIN BUTTON STYLE
				if( $('#user-login').get(0) ) {
					$('#user-login').find('#edit-submit').addClass('button-blue');
				}

				$('a[data-popup]').live('click', function(event){
					event.preventDefault();

					window.open($(this).attr('href'));
				});

				//CHANGE THE LINK FOR REGISTER WITH LOGIN LINK
				// if( $('.header-menu').get(0) ) {
				//	var externalLink = $('.sign-in').find('a').attr('href');
				//	$('.header-menu').find('.last').find('a').attr('href', externalLink);
				//}

        // Adding a view video link to videos
				if( $('#lightbox').get(0) ) {
				  $('a[rel]').each(function(index){
				    $(this).click(function(){
      				$('#bottomNavLink').remove();
      				if ($(this).attr('rel') == 'lightvideo') {
        				var text = 'If the video does not play automatically, click here';
        				var href = $('a[rel=lightvideo]').attr('href');
        				var title = $('a[rel=lightvideo] img').attr('alt');
        				if (typeof title != 'undefined') {
        				  title = text;
        				}
        				if (typeof href != 'undefined') {
          				$('#bottomNav').prepend('<a id="bottomNavLink" title="' + title + '" href="' + href + '" target="_blank">If the video does not play automatically, click here</a>');
        				}
      				}
    				});
   				});
				}
				
			}
		}
})(jQuery);
